﻿using ScFramework.Core;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if GUI_DEBUG
using UnityEditor;


[DebugCmdType("控制")]
public static class ControlDebug
{
    [DebugCmd("退出程序")]
    public static string Exit()
    {
        UnityEditor.EditorApplication.isPlaying = false;
        return "退出成功";
    }

    [DebugCmd("单帧模拟物理")]
    public static string SimulateOneDeltaTime()
    {
        Physics2D.Simulate(Time.fixedDeltaTime);
        return "模拟了一帧物理";
    }

    [DebugCmd("自动模拟物理")]
    public static string AutoSimulation()
    {
        Physics2D.autoSimulation = true;
        return "已设置为自动模拟物理";
    }

    [DebugCmd("不自动模拟物理")]
    public static string NotAutoSimulation()
    {
        Physics2D.autoSimulation = false;
        return "已设置为不自动模拟物理";
    }

    private static Main _main = null;

    private static Main main
    {
        get
        {
            if (_main == null)
            {
                _main = GameObject.FindObjectOfType<Main>();
            }

            return _main;
        }
    }

    //[DebugCmd("切换流程","流程名称")]
    public static string ChangeProcedure(string procedureName)
    {
        if (main == null)
        {
            return "Main function not found";
        }
        else
        {
            try
            {
                main.Get<ProcedureManager>().ChangeTo(procedureName);
            }
            catch (KeyNotFoundException e)
            {
                return ("流程切换的参数有误" + e);
            }
            catch (ArgumentException)
            {
                return "Procedure not found";
            }

            return "Success to change procedure";
        }
    }
}
#endif